package com.yitianyigexiangfa.designpattern.facade.hometheater;

import com.yitianyigexiangfa.designpattern.facade.hometheater.subsystem.Amplifier;
import com.yitianyigexiangfa.designpattern.facade.hometheater.subsystem.CdPlayer;
import com.yitianyigexiangfa.designpattern.facade.hometheater.subsystem.DvdPlayer;
import com.yitianyigexiangfa.designpattern.facade.hometheater.subsystem.PopcornPopper;
import com.yitianyigexiangfa.designpattern.facade.hometheater.subsystem.Projector;
import com.yitianyigexiangfa.designpattern.facade.hometheater.subsystem.Screen;
import com.yitianyigexiangfa.designpattern.facade.hometheater.subsystem.TheaterLights;
import com.yitianyigexiangfa.designpattern.facade.hometheater.subsystem.Tuner;

/**
 * @author Bill Lau
 * @date 2018-01-18
 */
public class HomeTheaterFacade {

    private Amplifier amplifier;
    private Tuner tuner;
    private DvdPlayer dvdPlayer;
    private CdPlayer cdPlayer;
    private Projector projector;
    private TheaterLights theaterLights;
    private Screen screen;
    private PopcornPopper popcornPopper;

    public HomeTheaterFacade(Amplifier amplifier, Tuner tuner,
                             DvdPlayer dvdPlayer,
                             CdPlayer cdPlayer,
                             Projector projector,
                             TheaterLights theaterLights,
                             Screen screen,
                             PopcornPopper popcornPopper) {
        this.amplifier = amplifier;
        this.tuner = tuner;
        this.dvdPlayer = dvdPlayer;
        this.cdPlayer = cdPlayer;
        this.projector = projector;
        this.theaterLights = theaterLights;
        this.screen = screen;
        this.popcornPopper = popcornPopper;
    }

    public void watchMovie(String movie) {
        System.out.println("Get ready to watch a movie...");
        popcornPopper.on();
        popcornPopper.pop();
        theaterLights.dim(10);
        screen.down();
        projector.on();
        projector.wideScreenMode();
        amplifier.on();
        amplifier.setDvd(dvdPlayer);
        amplifier.setStereoSound();
        amplifier.setVolume(5);
        dvdPlayer.on();
        dvdPlayer.play(movie);
    }

    public void endMovie() {
        System.out.println("Shutting movie theater down...");
        popcornPopper.off();
        theaterLights.on();
        screen.up();
        projector.off();
        amplifier.off();
        dvdPlayer.stop();
        dvdPlayer.eject();
        dvdPlayer.off();
    }

}
